﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PRE.Catalog
{
    public partial class FrmXemphieuthu : PRE.Catalog.FrmBase
    {
        DAL.EntitesDAL.PhieuthuDAL _dal = new DAL.EntitesDAL.PhieuthuDAL();
        DAL.EntitesDAL.KhoahocDAL _dal1 = new DAL.EntitesDAL.KhoahocDAL();

        public FrmXemphieuthu()
        {
            InitializeComponent();
        }

        private void FrmXemphieuthu_Load(object sender, EventArgs e)
        {
            PerformRefresh();
        }

        #region Override

        /// <summary>
        /// Perform when click add button
        /// </summary>
        protected override void PerformAdd()
        {
            base.PerformAdd();
        }

        /// <summary>
        /// Perform when click cancel button
        /// </summary>
        protected override void PerformCancel()
        {
           base.PerformCancel();
        }

        /// <summary>
        /// Perform when click delete button
        /// </summary>
        /// <returns></returns>
        protected override void PerformDelete()
        {
            base.PerformDelete();
        }

        /// <summary>
        /// Perform when click edit button
        /// </summary>
        protected override void PerformEdit()
        {
            base.PerformEdit();
        }

        /// <summary>
        /// Perform when click print button
        /// </summary>
        protected override void PerformPrint()
        {
            base.PerformPrint();
        }

        /// <summary>
        /// Load data or perform when click refresh button
        /// </summary>
        protected override void PerformRefresh()
        {
            ReadOnlyControl();
            LoadData();
            ChangeStatus_HD();

            if (_dtb != null)
            {
                // Binding data
                ClearDataBindings();
                if (_dtb.Rows.Count > 0) DataBindingControl();
            }

            base.PerformRefresh();
        }

        /// <summary>
        /// Perform when click save button
        /// </summary>
        protected override void PerformSave()
        {
            base.PerformSave();
        }

        /// <summary>
        /// Reset all input control
        /// </summary>
        protected override void ResetText()
        {
            base.ResetText();
        }

        /// <summary>
        /// Clear data binding
        /// </summary>
        protected override void ClearDataBindings()
        {
            txtSoHD.DataBindings.Clear();
            txtHoten.DataBindings.Clear();
            dteNgaylap.DataBindings.Clear();
            txtSotien.DataBindings.Clear();
            txtBangchu.DataBindings.Clear();
            txtGhichu.DataBindings.Clear();

            base.ClearDataBindings();
        }

        /// <summary>
        /// Add data binding
        /// </summary>
        protected override void DataBindingControl()
        {
            txtSoHD.DataBindings.Add("EditValue", _dtb, ".SoHD");
            txtHoten.DataBindings.Add("EditValue", _dtb, ".HoTen");
            dteNgaylap.DataBindings.Add("EditValue", _dtb, ".Ngaylap");
            txtSotien.DataBindings.Add("EditValue", _dtb, ".Sotien");
            txtBangchu.DataBindings.Add("EditValue", _dtb, ".Bangchu");
            txtGhichu.DataBindings.Add("EditValue", _dtb, ".Ghichu");

            base.DataBindingControl();
        }

        /// <summary>
        /// Set read only control on form
        /// </summary>
        /// <param name="isReadOnly">Read only is trule else normal</param>
        protected override void ReadOnlyControl(bool isReadOnly = true)
        {
            grcMain.Enabled = isReadOnly;

            base.ReadOnlyControl(isReadOnly);
        }

        protected override void PerformSearch()
        {
            base.PerformSearch();
        }

        protected override bool UpdateObject()
        {
            return base.UpdateObject();
        }

        /// <summary>
        /// Insert object
        /// </summary>
        /// <returns>True if successful else false</returns>
        protected override bool InsertObject()
        {
            return base.InsertObject();
        }

        /// <summary>
        /// Load data
        /// </summary>
        protected override void LoadData()
        {
            DataTable tmp = _dal1.Select();
            if (tmp != null)
                cboKhoahoc.Properties.DataSource = tmp;
            cboKhoahoc.ItemIndex = -1;
            base.LoadData();
        }
        #endregion

        private void cboKhoahoc_EditValueChanged(object sender, EventArgs e)
        {
            string _makhoa = cboKhoahoc.EditValue + "";
            _dtb = _dal.Select_View(_makhoa);

            if (_dtb != null)
            {
                grcMain.DataSource = _dtb;
            }

            if (_dtb != null)
            {
                // Binding data
                ClearDataBindings();
                if (_dtb.Rows.Count > 0) DataBindingControl();
            }
        }


    }
}
